package controller.servletRemocao;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.classe.Cliente;
import model.classesDAO.ClienteDAO;
import model.factory.Fabrica;

/**
 * Servlet implementation class ServletRemoverCliente
 */
@WebServlet("/ServletRemoverCliente")
public class ServletRemoverCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletRemoverCliente() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String fakeid = request.getParameter("id");
		int id = Integer.parseInt(fakeid);
		ClienteDAO clidao = Fabrica.getClienteDAO();
		Cliente cliente = new Cliente();
		cliente.setId(id);
		cliente = clidao.pesquisarID(id);
		if(cliente != null)
			clidao.remover(cliente);
		else
			System.out.println("Usuario nao encontrado");
		
		RequestDispatcher redir = request.getRequestDispatcher("index.jsp");
		redir.forward(request, response);
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
